home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / 386p_200.zip / PCSPEAK.ASM < prev    next >
Assembly Source File  |  1995-01-13  |  7KB  |  174 lines

  1. ; DO NOT USE THIS, I JUST STARTED RECODING IT FOR XSD
  2.         align dword
  3. ; current sound data        
  4. _SoundLen   dd      0  ; default = zero sound lenght
  5. _SoundPtr   dd      0  ; default = null, points to already decode sound data
  6.                        ; the installed sound driver must play
  7. ; default sound data                       
  8. _DSoundLen  dd      0  ; default = zero , default sound lenght                                     
  9. _DSoundPtr  dd      0  ; default = null , default sound
  10.  
  11.          align byte
  12.          
  13. _SoundOn  db 0 ; Set this to turn on sound generation, all sound driver must
  14.                ; refer to this flag to control sound output
  15. _DSoundOn db 0 ;ditto for the default sound insertion at end of sound
  16.                           
  17.  
  18.  Buzzing    db      0 ; are we currently producing sound ? (private var.)
  19.  
  20. ; decrementi di contatore usati come riferimento
  21. PWMTICK   = 149           ; conteggio equivalente a 8008Hz
  22.  
  23.  
  24.         public _InstallPWM
  25.  
  26. _InstallPWM:
  27.         ; install irqs & set up voc_table
  28.         pushad
  29.         ; initialize internal vars
  30.         mov Buzzing,0
  31.         mov _SoundOn,0
  32.         mov _DSoundOn,0
  33.         mov _SoundLen,0
  34.         mov _SoundPtr,0
  35.         mov _DSoundLen,0
  36.         mov _DSoundPtr,0
  37. ; set voc_table
  38.         mov esi,offset pwm_table
  39.         mov edi,offset voc_table
  40.         mov eax,0
  41.         mov ecx,64
  42. set_up_voc_table:        
  43.         movsd
  44.         dec ecx
  45.         jne set_up_voc_table
  46.         cli
  47.         ; first install the real mode side
  48.         cmp _386Man,IS_DPMI
  49.         je @nopwreflex
  50.         mov al,21h
  51.         mov V86ax,2508h
  52.         mov V86ds,code16
  53.         mov V86dx,offset code16:IRQ0_RISR
  54.         int 33h
  55. @nopwreflex:        
  56.         ; then the protected mode side (it works only this way in DPMI)
  57.         mov bl,0
  58.         mov edx,offset IRQ0_ISR
  59.         call _SetIRQ
  60.         mov ebx,F8008 ; 8008Hz count
  61.         cmp _386Man,IS_DPMI
  62.         jne @vcpispeed
  63.         shl ebx,1 ; freq to 4004Hz
  64. @vcpispeed:        
  65.         mov play_rate,ebx ; set playback frequency for voc converter
  66.         
  67.         mov al,T_SET0   ; set programmable interval timer 0 to 8008Hz or 4004Hz
  68.         out PIT_CTRL,al ;
  69.         mov al,bl       ;
  70.         out PIT0,al     ;
  71.         mov al,bh       ;
  72.         out PIT0,al     ;
  73.         
  74.         sti
  75.         ; no need to initialize time counters
  76.         ; InstallPFLP already did it
  77.         popad
  78.         ret         
  79.         
  80. ; PWM SOUND SPEAKER DRIVER
  81.  
  82.  zarp_sound:
  83.         cmp _DSoundOn,0
  84.         je dont_buzz
  85.         mov eax,_DSoundLen
  86.         dec eax
  87.         mov ebx,_DSoundPtr
  88.         mov _SoundLen,eax
  89.         jmp doit_again
  90.         
  91.  dont_buzz:
  92.         cmp Buzzing,0
  93.         je getoutsound
  94.         mov Buzzing,0
  95.         ; turn speaker OFF
  96.         in      al, 61h                 ;Read I/O port B into AL
  97.         and     al, 11111100b           ;mask lower two bits
  98.         out     61h, al                 ;to turn off speaker
  99.         pop ebx
  100.         pop eax
  101.         ret
  102.  
  103. DoTheSound:
  104.         push eax
  105.         push ebx
  106.         ; ds is on correct segment
  107.         cmp _SoundOn,0
  108.         je  dont_buzz    ; no sound if sound flag is off
  109.         cmp _SoundLen,0
  110.         je  zarp_sound   ; no sound if at end of "soundtrack"
  111.         dec _SoundLen    ; decrease "soundtrack" lenght
  112.  
  113.         mov     ebx,_SoundPtr    ;get current count pointer
  114. doit_again:
  115.         mov     al,[ebx]            ; count into AX
  116.         inc     ebx                 ; & update sound pointer
  117.         mov     _SoundPtr,ebx       ; (only offset is changed)
  118.         mov     ah,al    ; copy count 
  119.         or      al,al         ; zero count sets speaker off
  120.         ;je      dont_buzz     ;
  121.         
  122.         mov     al,P_SET2S
  123.         out     PIT_CTRL,al      
  124.         mov     al,ah
  125.         out     PIT2, al             
  126.  
  127.         cmp Buzzing,0
  128.         jne getoutsound
  129.         mov Buzzing,1
  130.         ; turn sound on
  131.         in      al, 61h                 ;read I/O port B into AL
  132.         or      al,3                    ;turn on bits 0 and 1
  133.         out     61h,al                  ;to turn on speaker
  134. getoutsound:
  135.         pop ebx
  136.         pop eax
  137.         ret
  138.  
  139. ;-----------------------------------------------------------------------------
  140. ; 8bit, not compressed VOC to "raw 8 bit pcm"
  141.           align dword
  142. voc_rate  dd ?
  143. play_rate dd ? ; playback sample rate and IRQ0 frequency under PWM sound
  144.  
  145.           align byte
  146. pwm_table db 1 , 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20
  147.           db 21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30
  148.           db 31,31,31,32,32,32,33,33,33,34,34,34,35,35,35,36,36,36,37,37          
  149.           db 37,38,38,38,39,39,39,40,40,40,41,41,41,42,42,42,43,43,43,44          
  150.           db 45,45,45,46,46,46,47,47,47,48,48,48,49,49,49,50,50,50,51,51
  151.           db 51,52,52,52,53,53,53,54,54,54,55,55,55,56,56,56,57,57,57,57
  152.           db 58,58,58,58,59,59,59,59,60,60,60,60,61,61,61,61,62,62,62,62          
  153.           db 63,63,63,63,63,64,64,64,64,64,65,65,65,65,65,66,66,66,66,66
  154.           db 67,67,67,67,67,68,68,68,68,68,69,69,69,69,69,70,70,70,70,70
  155.           db 71,71,71,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,72
  156.           db 73,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,74,74
  157.           db 75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75
  158.           db 75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75
  159.           
  160. voc_table db 1 , 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20
  161.           db 21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30
  162.           db 31,31,31,32,32,32,33,33,33,34,34,34,35,35,35,36,36,36,37,37          
  163.           db 37,38,38,38,39,39,39,40,40,40,41,41,41,42,42,42,43,43,43,44          
  164.           db 45,45,45,46,46,46,47,47,47,48,48,48,49,49,49,50,50,50,51,51
  165.           db 51,52,52,52,53,53,53,54,54,54,55,55,55,56,56,56,57,57,57,57
  166.           db 58,58,58,58,59,59,59,59,60,60,60,60,61,61,61,61,62,62,62,62          
  167.           db 63,63,63,63,63,64,64,64,64,64,65,65,65,65,65,66,66,66,66,66
  168.           db 67,67,67,67,67,68,68,68,68,68,69,69,69,69,69,70,70,70,70,70
  169.           db 71,71,71,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,72
  170.           db 73,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,74,74
  171.           db 75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75
  172.           db 75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75
  173.  
  174.